package czx.wt.system.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import czx.wt.system.mapper.UserRoleMapper;
import czx.wt.system.pojo.UserRole;
import czx.wt.system.service.IUserRoleService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: ChenZhiXiang
 * @Date: 2019/6/19 23:09
 * @Description: 用户角色实体类
 */
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements IUserRoleService {

    @Override
    public Integer[] getRoleByUserIds(Integer userId) {
        EntityWrapper<UserRole> wrapper = new EntityWrapper<>();
        wrapper.eq("user_id",userId);
        List<UserRole> userRoles = baseMapper.selectList(wrapper);
        Integer[] roleIds = new Integer[userRoles.size()];
        for (int i = 0;i < userRoles.size();i++){
            roleIds[i] = userRoles.get(i).getRoleId();
        }
        return roleIds;
    }
}
